const userModel = require('../models/userModel')

// 获取所有用户
const getAllUsers = async () => {
  return await userModel.getAllUsers()
}

// 创建新用户
const createUser = async (params) => {
  return await userModel.createUser(params)
}

const getUserById = async (id) => {
  return await userModel.getUserById({ key: 'id', value: id })
}

const getUserByName = async (name) => {
  const users = await userModel.getUserByParam({ key: 'name', value: name })
  if (users.length == 0) {
    // return await userModel.createUser({ name })
    throw new Error('没有该驻场人员，请联系管理员！')
  } else {
    return users[0]
  }
}

module.exports = {
  getAllUsers,
  createUser,
  getUserById,
  getUserByName
}
